<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <title>用户登录</title>
</head>
<body>

<link rel="stylesheet" href="https://cdn.bootcss.com/sweetalert/0.5.0/sweet-alert.css"/>
<link rel="stylesheet" href="https://zqjscss.cdn.bcebos.com/css/style.css"/>
<script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script src="/static/js/novel.js"></script>
<script src="https://zqjscss.cdn.bcebos.com/js/apps.js"></script>
<div class="topbar">
    <div class="topbar-con">
        <div class="topbar-sethome">
            <a href="javascript:winSetHP();">将本站设为首页</a>
        </div>
        <div class="topbar-addfavorite">
            <a href="javascript:winAddFav()">收藏笔趣阁</a>
        </div>
        <div class="topbar-right">
            <script>PCLogin()</script>
        </div>
    </div>
</div>

<div class="header">
    <h1 class="logo"><a href="/">笔趣阁</a></h1>
    <form action="/ar.php" class="search-form" id="form">
        <input class="input-text input-key" id="keyWord" name="keyWord" type="text" maxlength="30"
               placeholder="可搜书名和作者，请您少字也别输错字。"/>
        <input type="button" class="btn-tosearch" value="搜索" title="搜索" onclick="check()"/>
    </form>
    <div class="m-user" style="color:#fff">
        <script>MLogin()</script>
    </div>
</div>

<ul class="nav">
    <li><a href="/">首页</a></li>
    <li><a rel="nofollow" href="/user/case.php">永久书架</a></li>
    <li><a href="/xuanhuanxiaoshuo/">玄幻奇幻</a></li>
    <li><a href="/xiuzhenxiaoshuo/">武侠仙侠</a></li>
    <li><a href="/dushixiaoshuo/">都市言情</a></li>
    <li><a href="/lishixiaoshuo/">历史军事</a></li>
    <li><a href="/kehuanxiaoshuo/">科幻灵异</a></li>
    <li><a href="/wangyouxiaoshuo/">网游竞技</a></li>
    <li><a href="/nvshengxiaoshuo/">女生频道</a></li>
    <li><a href="/paihangbang/">排行榜单</a></li>
    <li><a href="/collect/">收藏榜单</a></li>
    <li><a href="/wanbenxiaoshuo/">完本小说</a></li>
    <li><a rel="nofollow" href="/reader/case.php">阅读记录</a></li>
</ul>
<ul class="m-nav">
    <li><a href="/paihangbang/">排行</a></li>
    <li><a href="/collect/">收藏</a></li>
    <li><a href="/wanbenxiaoshuo/">完本</a></li>
    <li><a href="/reader/case.php">阅读记录</a></li>
    <li><a href="/user/case.php" rel="nofollow">书架</a></li>
</ul>
<script>createApp()</script>
<div class="container">
    <form name="frmLogin" id="frmLogin" method="post">
        <table class="grid" width="580">
            <caption>
                用户注册
            </caption>
            <tbody>
            <tr>
                <td width="28%">邮箱：</td>
                <td>
                    <input type="text" class="text" id="username" maxlength="30" value=""/>
                </td>
            </tr>
            <tr>
                <td width="28%">验证码：</td>
                <td>
                    <input type="password" class="text" id="password" maxlength="20" value=""/>
                </td>
            </tr>
            <tr>
                <td width="28%">有效期：</td>
                <td>
                    <input type="text" class="vcode" id="vcode" maxlength="20" value=""/>
                    <input type="button" class="vcode" id="vcode_btn" onclick="sendVcode()" maxlength="20" value="发送验证码"/>
                </td>
            </tr>
            <tr>
                <td width="28%"> &nbsp;</td>
                <td>
                    <input type="hidden" name="action" id="action" value="login"/>
                    <input type="button" class="button" name="submit" onsubmit="register()" id="submit" value="提 交"/>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>
<script>createApp()</script>
<div class="footer" id="footer">
    <div class="pc-footer">
        <p>本站所有小说为转载作品，所有章节均由网友上传，转载至本站只是为了宣传本书让更多读者欣赏。</p>
    </div>
    <div class="m-footer">
        <a href="/">首页</a>
        <a href="/user/case.php" rel="nofollow">我的书架</a>
        <a href="/reader/case.php" rel="nofollow">阅读记录</a>
        <a href="https://mgzs.cdn.bcebos.com/appdown.html?w=tg12">客户端</a>
        <a href="#">顶部↑</a>
    </div>
</div>

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
    const HEAD = '/api/v1/user'
    const LOGIN = '/login'
    const REGISTER = '/register'
    const SEND_CODE = '/sendVCode'

    /**
     * 发送方法
     */
    function send(type, url, data, successMethod, errorMethod) {
        $.ajax({
            type: type,
            url: url,
            data: data,
            success: successMethod,
            error: errorMethod
        })
    }

    /**
     * 发送验证码
     */
    function sendVcode() {
        let username = $('#username').val()
        let password = $('#password').val()

        send('post', HEAD + SEND_CODE, {
            name: username,
            password: password
        }, (repo) => {
            if (repo.code) {
                // todo 发送成功
                alert('发送成功')
            } else {
                // todo 发送失败
                alert(repo.msg)
            }
        }, (err) => {
            // 请求失败
            alert("请求失败")
            console.log(err)
        })
    }

    /**
     * 注册
     */
    function register() {
        let username = $('#username').val()
        let password = $('#password').val()
        let vcode = $('#vcode').val()

        send('post', HEAD + REGISTER, {
            name: username,
            password: password,
            vcode: vcode
        }, (repo) => {
            if (repo.code) {
                // todo 发送成功
                location.href = './index.html'
            } else {
                // todo 发送失败
                alert(repo.msg)
            }
        }, (err) => {
            // 请求失败
            alert("请求失败")
            console.log(err)
        })
    }

</script>
</body>
</html>